package com.yuexinduo.education.ui;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.yuexinduo.education.R;
import com.yuexinduo.education.adapter.TeacherAdapter;
import com.yuexinduo.baselibrary.base.BaseMvpActivity;
import com.yuexinduo.education.fragment.TeacherElseFragment;
import com.yuexinduo.education.fragment.TeacherUnderwayFragment;

import java.util.ArrayList;
import java.util.List;

public class MyTeacherActivity extends BaseMvpActivity implements View.OnClickListener {
    private ImageView back;
    private TextView top;
    private TextView teacherUnderway;
    private TextView teacherElse;
    private ViewPager viewPager;
    private List<Fragment> fragmentList = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (position == 0){
                    teacherUnderway.setTextColor(getResources().getColor(R.color.red));
                    teacherElse.setTextColor(getResources().getColor(R.color.black));
                }else {
                    teacherElse.setTextColor(getResources().getColor(R.color.red));
                    teacherUnderway.setTextColor(getResources().getColor(R.color.black));
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    protected int bindLayout() {
        return R.layout.activity_my_teacher;
    }

    @Override
    protected Activity getActivity() {
        return this;
    }

    @Override
    protected void initCreate() {
        back = (ImageView) findViewById(R.id.back);
        top = (TextView) findViewById(R.id.top);

        teacherUnderway = (TextView) findViewById(R.id.teacher_underway);
        teacherElse = (TextView) findViewById(R.id.teacher_else);

        viewPager = (ViewPager) findViewById(R.id.viewPager);
        back.setOnClickListener(this);
        teacherUnderway.setOnClickListener(this);
        teacherElse.setOnClickListener(this);
        top.setText("我的老师");

        fragmentList.add(new TeacherUnderwayFragment());
        fragmentList.add(new TeacherElseFragment());

        TeacherAdapter teacherAdapter = new TeacherAdapter(getSupportFragmentManager(), FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT, fragmentList);
        viewPager.setAdapter(teacherAdapter);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.back:
                finish();
                break;
            case R.id.teacher_underway:
                viewPager.setCurrentItem(0);
                break;
            case R.id.teacher_else:
                viewPager.setCurrentItem(1);
                break;
        }
    }
}